/**
 *
 */
package jp.seraph.same.view.cui;

import jp.seraph.cui.AbstractCommand;
import jp.seraph.cui.InternalConsole;
import jp.seraph.cui.Mode;
import jp.seraph.cui.StringData;
import jp.seraph.cui.StringDataType;
import jp.seraph.cui.SystemNode;
import jp.seraph.cui.SystemNodeType;
import jp.seraph.jsade.math.Angle;
import jp.seraph.jsade.model.JointIdentifier;
import jp.seraph.jsade.model.JointIdentifierContainer;

/**
 *
 *
 */
public class SetAngleCommand extends AbstractCommand {
    public SetAngleCommand(JointIdentifierContainer aIdContainer, Mode aParent, InternalConsole aConsole){
        super(aParent, aConsole);

        mIdContainer = aIdContainer;
    }

    private JointIdentifierContainer mIdContainer;

    /**
     *
     * @see jp.seraph.cui.AbstractCommand#executeImpl(jp.seraph.cui.SystemNode[], int)
     */
    @Override
    protected void executeImpl(SystemNode[] aArgs, int aArgListIndex) {
        PoseData tPose = (PoseData)aArgs[0];
        String tJointName = ((StringData)aArgs[1]).getData();
        String tAngleString = ((StringData)aArgs[2]).getData();

        JointIdentifier tId = mIdContainer.getIdentifier(tJointName);
        Angle tAngle = Angle.createAngleAsDegree(Double.parseDouble(tAngleString));

        tPose.setAngle(tId, tAngle);
    }

    /**
     *
     * @see jp.seraph.cui.Command#getArgumentTypes()
     */
    public SystemNodeType[][] getArgumentTypes() {
        SystemNodeType[][] tResult = new SystemNodeType[1][];
        tResult[0] = new SystemNodeType[]{PoseDataType.getInstance(), StringDataType.getInstance(), StringDataType.getInstance()};

        return tResult;
    }

    /**
     *
     * @see jp.seraph.cui.Command#getHelp()
     */
    public String getHelp() {
        return "set PoseData \"JointId\", \"Angle(Degree)\" : set Pose Angle";
    }

    /**
     *
     * @see jp.seraph.cui.SystemNode#getName()
     */
    public String getName() {
        return "set";
    }

    /**
     *
     * @see jp.seraph.cui.SystemNode#getType()
     */
    public SystemNodeType getType() {
        return SetAngleCommandType.getInstance();
    }

    /**
     *
     * @see jp.seraph.cui.SystemNode#isRoot()
     */
    public boolean isRoot() {
        return false;
    }

}
